<template>
  <div class="card">
    <el-popover placement="bottom" v-model="visible" trigger="manual" width="200">
      <div class="searchClick">
        <ul>
          <li v-for="(item, index) in dataList" @click="selectSession(item)" :key="index"  class="clickLi">
            <img class="avatar" width="30" height="30" :src="item.img ? item.img : moAvator" />
            <p class="name" style="padding-left:8px;color:#303133;font-size:14px">{{ item.name }}</p>
          </li>
        </ul>
      </div>
      <input style="width:90%;border-color: #BEC6D3;border-radius: 4px;border: 1px solid #BEC6D3;" class="search" type="text" placeholder="请按enter键搜索" @keyup="onKeyup" slot="reference" @click="visible = !visible" />
    </el-popover>
    <!-- <div class="search">
      <div class="searchBox">
        <el-autocomplete @select="handleSelect" :fetch-suggestions="querySearchAsync" popper-class='seachShipList' :popper-append-to-body="false" value-key="nameCn" placeholder="搜索..." v-model="searchName" size="mini" clearable @keyup="onKeyup">
          <i slot="prefix" class="el-icon-search font-b" style="color:#96A3B7"></i>
        </el-autocomplete>
      </div>
    </div> -->
  </div>
</template>

<script>
import { actions } from "../../../store/index";

export default {
  data() {
    return {
      searchName: "",
      visible: false,
      dataList: [],
      selectList: [],
      moAvator: require("@/assets/icon/morentouxiang.svg"),
      currentId:''
    };
  },
  vuex: {
    actions: actions,
    getters: {
      user: ({ user }) => userName,
      filterKey: ({ filterKey }) => filterKey,
    },
  },
  computed: {
    user() {
      return this.$store.state.userName;
    },
    current(){
      return this.$store.state.currentSessionId;
    }
  },
  watch: {
    current(newValue, oldValue) {
      // console.log(newValue);
      this.currentId = newValue
    }
  },
  methods: {
    //选中
    selectSession(item) {
      item.messages = []
      this.visible = false
      let peopleList = this.$store.state.sessions
      let isIndex = peopleList.findIndex(res=>{
        return res.accNo == item.accNo
      })
      if(isIndex != -1) return
      this.selectList.push(item)
      this.$store.commit("USER_DATA",this.selectList);
    },
    onKeyup(e) {
      if (e.keyCode == 13) {
        this.userName = e.target.value;
        this.getUserList();
        // this.search(e.target.value);
      }
    },
    getUserList() {
      this.$http
        .get(
          `/${this.$ServiceName}/api/external/im/${this.$version}/listuser?username=${this.userName}`
        )
        .then((res) => {
          if (res.data.code != "0000") {
            // return this.$message.error(res.data.msg)
            console.log(res);
          }
          console.log(res);
          this.dataList = res.data.data
          // this.$store.commit("USER_DATA", res.data.data);
          // this.personForm = res.data.data
        });
    },
  },
};
</script>

<style scoped lang="less">
.clickLi{
  margin: 10px 0;
  cursor: pointer;
}
.avatar,
.name {
  vertical-align: middle;
}
.avatar {
  border-radius: 2px;
}
.name {
  display: inline-block;
  margin: 0 5px 0 15px;
  color: rgb(36, 32, 32);
}
.active {
  background-color: #e8eaec !important;
}
.searchClick {
  max-height: 300px;
  overflow-y: scroll;
}
// 搜索框
.searchBox {
  // margin-right: 20px;
  /deep/ .el-input__inner {
    width: 180px;
    border-radius: 50px;
    border-color: #bec6d3;
    background: #fff;
    color: #909399;
    transition: all 0.5s ease 0s;
  }

  /deep/ .el-input__inner:focus {
    width: 200px;
  }

  /deep/ .seachShipList {
    width: 200px !important;
  }

  /deep/ .el-input__prefix {
    left: 10px;
    color: #96a3b7;
    display: flex;
    align-items: center;
  }
}
.card {
  padding: 12px;
  background: #fff;
  //   border-bottom: solid 1px #24272c;

  footer {
    margin-top: 10px;
  }

  .avatar,
  .name {
    vertical-align: middle;
  }
  .avatar {
    border-radius: 2px;
  }
  .name {
    display: inline-block;
    margin: 0 0 0 15px;
    font-size: 16px;
  }
  .search {
    padding: 2px 10px;
    // width: 100%;
    font-size: 12px;
    // color: #fff;
    height: 22px;
    line-height: 24px;
    // border: solid 1px #3a3a3a;
    border-radius: 4px;
    outline: none;
    // background-color: #26292e;
  }
}
</style>
